﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IrrKlang;
using SoundsLibrary;

namespace RTS
{
    public partial class SoundLibrary : UserControl
    {
        private List<String> _sounds;
        private List<String> _names;
        private SoundLibraryModel _data = new SoundLibraryModel();
        public ISoundEngine engine = new ISoundEngine();
        public SoundLibrary()
        {

            InitializeComponent();

        }

        private void addFile(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialog = new
                System.Windows.Forms.OpenFileDialog() { Multiselect = true };
           
            dialog.Filter = "All playable files (*.mp3;*.ogg;*.wav;*.mod;*.it;*.xm;*.it;*.s3d)|*.mp3;*.ogg;*.wav;*.mod;*.it;*.xm;*.it;*.s3d";
            dialog.FilterIndex = 0;

            if (dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                foreach (String item in dialog.FileNames)
                {
                    this._data.addSound(item);
                }
               

                

            }
        }
        private void addSound(string path, string name)
        {
            this._sounds.Add(path);
            this._names.Add(name);
        }
        private void addSound(string path)
        {
            this.addSound(path, path.Substring(path.LastIndexOf("\\") + 1));
        }
        private void SoundLibrary_Load(object sender, EventArgs e)
        {
            _sounds = new List<string>();
            _names = new List<string>();

            this.addSound("../../Resources/bass1.wav");
            this.addSound("../../Resources/kick.wav");
            this.soundsList.DataSource = _names;
        }


        public void playSelected(object sender, EventArgs e)
        {
            ISound currentlyPlayingSound = engine.Play2D("../../Resources/basse1.wav", true);
            currentlyPlayingSound.Paused = false;
        }

        


    }

}
